import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:kasax_demos2/day16_getx/sample_demo_getx_controller.dart';

class PageTwo extends StatefulWidget {
  const PageTwo({Key? key}) : super(key: key);

  @override
  _PageTwoState createState() => _PageTwoState();
}

class _PageTwoState extends State<PageTwo> {
  @override
  Widget build(BuildContext context) {
    final oneControler = Get.find<PageOneController>();
    final twoController = Get.put(TwoController());
    return Scaffold(
      appBar: AppBar(
        title: Text("PageTwo"),
      ),
      body: Center(
        child: Column(
          children: [
            GetBuilder<TwoController>(
              builder: (controler) {
                return Text("这个是One传递过来的参数：${twoController.msg}");
              },
            ),
            GetBuilder<TwoController>(
              builder: (controler) {
                return Text("count点击次数：${twoController.count}");
              },
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          oneControler.incremnt();
          twoController.increment();
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}

class TwoController extends GetxController {
  var count = 0;
  var msg = "";

  @override
  void onReady() {
    var map = Get.arguments;
    msg = map['msg'];
    update();
    super.onReady();
  }

  increment() {
    count++;
    update();
  }
}
